package unit20.imageViewer;

import java.awt.Dimension;
import java.awt.Image;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;

public class ImageViewerBean extends JLabel{
	private Path path=null;
	private static final  int X=200;
	private static final int Y=200;
	public ImageViewerBean() {
		// TODO Auto-generated constructor stub
		setBorder(BorderFactory.createEtchedBorder());
	}
	
	public void setFileName(String fileName) throws IOException{
		path=Paths.get(fileName);
		try(InputStream in=Files.newInputStream(path)){
			setIcon((Icon) ImageIO.read(in));
		}catch (Exception e) {
			// TODO: handle exception
			path=null;
			setIcon(null);
		}
	}
	public String getFileName(){
		if(path==null)
			return "";
		else
			return path.toString();
	}
	public Dimension getPreferredSize(){
		return new Dimension(X, Y);
	}
}
